<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "users_product".
 *
 * @property int $id ID
 * @property int $user_id
 * @property int $product_id
 * @property int $status 1= 有效   2=已转让
 * @property string $ctime
 * @property string $utime
 */
class UsersProduct extends \yii\db\ActiveRecord {
    /**
     * {@inheritdoc}
     */
    public static function tableName() {
        return 'users_product';
    }

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['user_id', 'product_id', 'status'], 'integer'],
            [['product_id', 'ctime', 'utime'], 'required'],
            [['ctime', 'utime'], 'safe'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'user_id' => 'User ID',
            'product_id' => 'Product ID',
            'status' => 'Status',
            'ctime' => 'Ctime',
            'utime' => 'Utime',
        ];
    }

    public function getUsers() {
        return $this->hasOne(Users::class, ['id' => 'user_id']);
    }

    public function getProduct() {
        return $this->hasOne(Product::class, ['id' => 'product_id']);
    }
}
